﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using StockNet.stocks;
using StockNet.stocks.yahoo;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace StockNet.Test
{
    [TestClass]
    public class StockNetTests
    {
        [TestMethod]
        public async Task GetTop100StockValuesSingle()
        {
            var stockClient = new YahooStocksClient();

            var symbols = new string[] { "AAPL", "ADBE", "ADI", "ADP", "ADSK", "AKAM", "ALTR", "ALXN", "AMAT", "AMGN", "AMZN", 
                "ATVI", "AVGO", "BBBY", "BIDU", "BIIB", "BRCM", "CA", "CELG", "CERN", "CHKP", "CHRW", "CHTR", "CMCSA", "COST", 
                "CSCO", "CTRX", "CTSH", "CTXS", "DISCA", "DISH", "DLTR", "DTV", "EBAY", "EQIX", "ESRX", "EXPD", "EXPE", "FAST",
                "FB", "FFIV", "FISV", "FOXA", "GILD", "GMCR", "GOOG", "GOOGL", "GRMN", "HSIC", "ILMN", "INTC", "INTU", "ISRG", 
                "KLAC", "KRFT", "LBTYA", "LLTC", "LMCA", "MAR", "MAT", "MDLZ", "MNST", "MSFT", "MU", "MXIM", "MYL", "NFLX", 
                "NTAP", "NVDA", "NXPI", "ORLY", "PAYX", "PCAR", "PCLN", "QCOM", "REGN", "ROST", "SBAC", "SBUX", "SIAL", "SIRI", 
                "SNDK", "SPLS", "SRCL", "STX", "SYMC", "TRIP", "TSCO", "TSLA", "TXN", "VIAB", "VIP", "VOD", "VRSK", "VRTX", 
                "WDC", "WFM", "WYNN", "XLNX" };

            var tasks = new List<Task>();
            foreach (var symbol in symbols)
            {
                var result = await stockClient.GetStockValues(symbol);
                var stock = result.FirstOrDefault();
                Assert.IsNotNull(stock, symbol + " is null");
                Assert.AreEqual(symbol, stock.Symbol, "symbols dont match");
                Assert.IsTrue(stock.PreviousClose > 0, "prev close is less than 0");
                Assert.IsTrue(stock.LastTradePrice > 0, "last trade is less than 0");
            }
        }


        [TestMethod]
        public async Task GetTop100StockValuesAll()
        {
            var stockClient = new YahooStocksClient();

            var symbols = new string[] { "AAPL", "ADBE", "ADI", "ADP", "ADSK", "AKAM", "ALTR", "ALXN", "AMAT", "AMGN", "AMZN", "ATVI", "AVGO", "BBBY", "BIDU", "BIIB", "BRCM", "CA", "CELG", "CERN", "CHKP", "CHRW", "CHTR", "CMCSA", "COST", "CSCO", "CTRX", "CTSH", "CTXS", "DISCA", "DISH", "DLTR", "DTV", "EBAY", "EQIX", "ESRX", "EXPD", "EXPE", "FAST", "FB", "FFIV", "FISV", "FOXA", "GILD", "GMCR", "GOOG", "GOOGL", "GRMN", "HSIC", "ILMN", "INTC", "INTU", "ISRG", "KLAC", "KRFT", "LBTYA", "LLTC", "LMCA", "MAR", "MAT", "MDLZ", "MNST", "MSFT", "MU", "MXIM", "MYL", "NFLX", "NTAP", "NVDA", "NXPI", "ORLY", "PAYX", "PCAR", "PCLN", "QCOM", "REGN", "ROST", "SBAC", "SBUX", "SIAL", "SIRI", "SNDK", "SPLS", "SRCL", "STX", "SYMC", "TRIP", "TSCO", "TSLA", "TXN", "VIAB", "VIP", "VOD", "VRSK", "VRTX", "WDC", "WFM", "WYNN", "XLNX" };

            var tasks = new List<Task>();

            var result = await stockClient.GetStockValues(symbols);

            foreach (var stock in result)
            {
                Assert.IsNotNull(stock.Symbol, "symbol is null");
                Assert.IsTrue(stock.PreviousClose > 0, "prev close is less than 0");
                Assert.IsTrue(stock.LastTradePrice > 0, "last trade is less than 0");
            }
        }

    }
}
